package net.yihang.demo.demo_quartz.jobs;

import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.time.LocalTime;

@Component
@Scope("prototype")
@DisallowConcurrentExecution
public class Job1 implements Job {
    private String name;

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {

        System.out.println("job1 trigger:" + context.getTrigger().getKey() + " " + context.getMergedJobDataMap().get("exception")
        +" "+ LocalTime.now());
        JobExecutionException e = new JobExecutionException("msg");
        if (((boolean) context.getMergedJobDataMap().get("exception"))) {

//        e.setUnscheduleFiringTrigger(true);
            e.setUnscheduleAllTriggers(true);
            throw e;
        }
    }
}
